package br.com.sig.security.business.model.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import br.com.sig.business.model.entity.BaseEntity;

@Entity
@Table(schema="sig_security", name="role")
public class Role extends BaseEntity {

	private static final long serialVersionUID = -5017824520579753974L;
	
	private String codigo;
	private String name;
	private Boolean active;
	private List<Permission> permissions;
	
	@Column(nullable=false, unique = true)
	@NotNull
	public String getCodigo() {
		return codigo;
	}
	
	public void setCodigo(String codigo) {
		this.codigo = codigo;
	}
	
	@Column(nullable=false, unique = true)
	@NotNull	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	@Column(nullable=false)
	@NotNull	
	public Boolean getActive() {
		return active;
	}
	
	public void setActive(Boolean active) {
		this.active = active;
	}

	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(
		schema="sig_security",
		name = "role_has_permission",
		joinColumns = @JoinColumn(name = "id_role", nullable = false),
		inverseJoinColumns = @JoinColumn(name = "id_permission", nullable = false)
	)	
	public List<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}
}